﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.IO;

namespace Client {
    class Program {
        static void Main(string[] args) {
            IPAddress serverIp = IPAddress.Parse("127.0.0.1");
            Console.WriteLine(serverIp);
            Socket echoSocket = new Socket(
                serverIp.AddressFamily,
                SocketType.Stream,
                ProtocolType.Tcp);
            echoSocket.Connect(serverIp, 13);
            string data;
            using (Stream echoServiceStream = new NetworkStream(echoSocket, true))
            using (StreamReader reader = new StreamReader(echoServiceStream))
            using (StreamWriter writer = new StreamWriter(echoServiceStream)) {
                writer.WriteLine("Yello!");
                writer.Flush();
                data = reader.ReadToEnd();
                Console.WriteLine("[from server]: {0}", data);
            }
            Console.ReadKey();
        }
    }
}